import {useState,useEffect} from 'react';

export const useRequest = (url)=>{
    const [data,setData] = useState([]);
    const [options,setOptions] = useState({tab:'all',page:1})
    useEffect(()=>{
        fetch(`${url}?tab=${options.tab}&page=${options.page}`)
            .then(res=>res.json())
            .then(res=>{
                res&&setData(res.data)
            })
            .catch((err)=>{console.log(err);})
    },[options])
    return [data,setOptions,options] 
}